package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiguCache;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;
	@Operation(summary = "根据用户id获取用户信息")
	@GuiguCache(cacheKey = RedisConstant.USER_INFO_PREFIX + "#{params[0]}",
			enableLock = true,
			lockName =RedisConstant.USER_INFO_LOCK_PREFIX + "#{params[0]}")
	@GetMapping("/getUserInfoVo/{userId}")
	public Result<UserInfo> getUserInfoVo(@PathVariable(value = "userId") Long userId){
		UserInfo userInfo = userInfoService.getById(userId);
		return Result.build(userInfo, ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "判断用户是否购买声音列表")
	@PostMapping("/userIsPaidTrack/{albumId}")
	public Result<Map<Long,Integer>> userIsPaidTrack(@PathVariable Long albumId, @RequestBody List<Long> trackIds){
		Map<Long,Integer> map = userInfoService.userIsPaidTrack(albumId,trackIds);
		return Result.build(map,ResultCodeEnum.SUCCESS);
	}

}

